﻿using System;
using System.Configuration;
using System.Xml;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 字符串元素
    /// </summary>
    public class StringContentElement : ConfigurationElement
    {
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public StringContentElement() { }
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="value"></param>
        public StringContentElement(string value)
        {
            this.Value = value;
        }

        /// <summary>
        /// 从配置信息中反序列化出内容
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="serializeCollectionKey"></param>
        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            this.Value = reader.ReadElementContentAsString();
        }

        /// <summary>
        /// 序列化内容到配置信息
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="serializeCollectionKey"></param>
        /// <returns></returns>
        protected override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
        {
            if (writer != null)
            {
                writer.WriteValue(this.Value);
            }
            return true;
        }

        /// <summary>
        /// 元素内容
        /// </summary>
        [ConfigurationProperty("data")]
        public virtual string Value
        {
            get
            {
                return this["data"] as string;
            }
            set
            {
                this["data"] = value;
            }
        }
    }
}
